﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sayeet
{
    public class JID
    {
        internal string username = null;
        internal string server = null;
        internal string resource = null;

        public JID(string u, string s)
        {
            username = u;
            server = s;
            resource = "";
        }

        public JID(string u, string s, string r)
        {
            username = u;
            server = s;
            resource = r;
        }

        public JID(string jid)
        {
            // TODO: clean up
            string[] s;
            string[] s1;
            s = jid.Split("@".ToCharArray());
            username = s[0];
            if (s.Length > 1)
            {
                s1 = s[1].Split("/".ToCharArray());
                server = s1[0];
                if (s1.Length > 1)
                    resource = s1[1];
                else
                    resource = "";
            }

            
        }

        public string Username
        {
            get
            {
                return username;
            }
            set
            {
                username = value;
            }
        }

        public string Server
        {
            get
            {
                return server;
            }
            set
            {
                server = value;
            }
        }

        public override string ToString()
        {
            string result = username + "@" + server;
            if (resource != "")
                result += "/" + resource;
            return result;
        }

        public string ToStringWithoutResource()
        {
            return username + "@" + server;
        }
    }
}
